package tile;

import java.util.ArrayList;

import tile.Dragon.DRAGON;
import tile.Wind.WIND;

public class Tile implements Comparable<Tile> {

	public enum SUIT {
		bamboo, character, dots, Wind(true), Dragon(true), Flower, Season;
		boolean isHonors;

		private SUIT() {
			this(false);
		}

		private SUIT(boolean honors) {
			isHonors = honors;
		}

		public boolean isHonors() {
			return isHonors;
		}
	}

	protected enum VIEW {
		M, H, C, W,
	}

	public VIEW status;
	public Object value;
	public SUIT suit;
	public boolean isWinner;

	public Tile(Object o) {
		value = o;
		isWinner = false;
	}

	public Tile(Object o, SUIT s) {
		this(o);
		suit = s;
		status = VIEW.H;
	}

	public Tile(String t) {
		char v = t.charAt(1);
		char s = t.charAt(0);
		switch (s) {
			case 'b':
				suit = SUIT.bamboo;
				value = Integer.parseInt(v + "");
				break;
			case 'c':
				suit = SUIT.character;
				value = Integer.parseInt(v + "");
				break;
			case 'd':
				suit = SUIT.dots;
				value = Integer.parseInt(v + "");
				break;
			case 'W':
				suit = SUIT.Wind;
				switch (v) {
					case 'e':
						value = WIND.EAST;
						break;
					case 'w':
						value = WIND.WEST;
						break;
					case 's':
						value = WIND.SOUTH;
						break;
					case 'n':
						value = WIND.NORTH;
						break;
				}
				break;
			case 'D':
				suit = SUIT.Dragon;
				switch (v) {
					case 'w':
						value = DRAGON.WHITE;
						break;
					case 'g':
						value = DRAGON.GREEN;
						break;
					case 'r':
						value = DRAGON.RED;
						break;
				}
				break;
			case 'F':
				suit = SUIT.Flower;
				value = Integer.parseInt(v + "");
				break;
			case 'S':
				suit = SUIT.Season;
				value = Integer.parseInt(v + "");
				break;
		}
		isWinner = false;
	}

	public Object getValue() {
		return null;
	};

	public static boolean isValid(Object o) {
		return false;
	}

	public static ArrayList<Object> getValidValues() {
		return null;
	}

	public String print() {
		return value + " of " + suit;
	};

	public int compareTo(Tile t) {
		if (t.status == status) {
			if (t.suit == suit) {
				if (t.value instanceof Integer) {
					return ((Integer) value).compareTo((Integer) t.value);
				}
				if (t.value instanceof WIND) {
					return ((WIND) value).compareTo((WIND) t.value);
				}
				if (t.value instanceof DRAGON) {
					return ((DRAGON) value).compareTo((DRAGON) t.value);
				}
			}
			return suit.compareTo(t.suit);
		}
		return status.compareTo(t.status);
	}

	/**
	 * Check if two tiles are equal
	 * 
	 * @param o
	 *            - An object to test equality to
	 * @return True if <code>o</code> is a Tile and <code>this.suit</code>
	 *         equals <code>o.suit</code> and <code>this.value</code> equals
	 *         <code>o.value</code>
	 */
	public boolean equals(Object o) {
		return o instanceof Tile && ((Tile) o).suit == suit
				&& ((Tile) o).value.equals(value);
	}

	public Tile clone() {
		return new Tile(value, suit);
	}

	public String toString() {
		return (isWinner?"w ":"")+(suit == SUIT.Dragon ? "D" : suit == SUIT.Wind ? "W" : suit
				.toString().substring(0, 1).toLowerCase())
				+ value.toString().substring(0, 1).toLowerCase();
	}

}
